#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    int cntReversePairs(vector<int> &nums, int l, int r)
    {
        if (l >= r)
            return 0;
        int mid = (l + r) / 2, cnt = 0, i = l, j = mid + 1;
        cnt = cntReversePairs(nums, l, mid) + cntReversePairs(nums, mid + 1, r);
        for (; i <= mid; ++i)
        {
            while (j <= r && ((long)nums[i] > 2 * (long)nums[j])) //广义逆序对,这里的常数2可以换成任何不小于正常数 C
            {
                cnt += mid - i + 1;
                j++;
            }
        }
        sort(nums.begin() + l, nums.begin() + r + 1);
        return cnt;
    }
    int reversePairs(vector<int> &nums)
    {
        return cntReversePairs(nums, 0, nums.size() - 1);
    }
};